<?php

namespace App\Api\Controller;

class Base extends \Controller {

    public function init() {
        // 设置语言
        lang(trim($this->request->get('language')));

        //设置返回数据的默认状态，如果没有调用$this->succ或$this->fail则会输出这里设置的默认值
        $this->assign(array('code' => 1, 'msg' => L('common/operation_success')));
    }

    /**
     * 重载render方法，以便支持json数据输出
     * @return string
     */
    public function render($compatible = null) {
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE');
        header('Access-Control-Allow-Headers: x-requested-with,content-type');
        header("Content-Type:" . \Http::mimeType('json') . "; charset=" . \Sys::getCfg('charset'));
        
        return json_encode(array_pretreat($this->vars));
    }

}
